import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:mtf/R.dart';
import 'package:mtf/app/modules/setting_module/setting_controller.dart';
import 'package:mtf/app/theme/app_colors.dart';
import 'package:mtf/app/widget/AppBarLeftTitle.dart';
import 'package:mtf/app/widget/SettingBar.dart';
/**
 * GetX Template Generator - fb.com/htngu.99
 * */

class settingPage extends GetView<settingController> {
  @override
  Widget build(BuildContext context) {
    controller.getCacheSize();
    return Scaffold(
      appBar: AppBarLeftTitle(title: "我的设置"),
      body: ListView.builder(
        itemBuilder: (context, index) {
          if (index == 0) {
            return Container(
              margin: EdgeInsets.symmetric(vertical: 15, horizontal: 10),
              decoration: BoxDecoration(
                  color: Colors.white, borderRadius: BorderRadius.circular(10)),
              child: Column(children: [
                SettingBar(
                  leftText: "个人资料",
                  rightIcon: SvgPicture.asset(
                    R.assetsImgIcSvgRight,
                    color: c_999999,
                  ),
                  showDivider: true,
                  onTap: () {
                    controller.clickMineInfo();
                  },
                ),
                SettingBar(
                  onTap: () {
                    controller.clickChangePsw();
                  },
                  leftText: "修改登录密码",
                  rightIcon: SvgPicture.asset(
                    R.assetsImgIcSvgRight,
                    color: c_999999,
                  ),
                  showDivider: true,
                ),
                SettingBar(
                  onTap: () {
                    controller.clickBankManager();
                  },
                  leftText: "银行卡管理",
                  rightIcon: SvgPicture.asset(
                    R.assetsImgIcSvgRight,
                    color: c_999999,
                  ),
                  showDivider: true,
                ),
                Obx(() {
                  return SettingBar(
                    onTap: (){
                      controller.updateApp();
                    },
                    leftText: "当前版本",
                    rightText: controller.versionObs.value,
                    rightTextColor: c_999999,
                    showDivider: true,
                  );
                }),
                Obx(() {
                  return SettingBar(
                    onTap: () {
                      showOkCancelAlertDialog(
                          context: Get.context!!,
                          title: '提示',
                          message: '确定要清楚缓存吗？',
                          cancelLabel: "取消",
                          okLabel: "确定",
                          useActionSheetForIOS: true,
                          defaultType: OkCancelAlertDefaultType.cancel)
                          .then((value) {
                        if (value.index == 0) {
                          print("cleanSize");
                          controller.cleanSize();
                        }
                      });
                    },
                    leftText: "清除缓存",
                    rightText: controller.cacheSize.value,
                    rightTextColor: c_999999,
                  );
                }),
              ]),
            );
          } else {
            return Container(
              margin: const EdgeInsets.only(top: 30, left: 10, right: 10),
              width: double.maxFinite,
              height: 48,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(24),
                color: c_f12f38,
              ),
              child: TextButton(
                  child: Text("退出登录",
                      style: TextStyle(
                          color: Colors.white,
                          fontSize: 16,
                          fontWeight: FontWeight.bold)),
                  onPressed: () async {
                    showOkCancelAlertDialog(
                        context: Get.context!!,
                        title: '提示',
                        message: '确定要退出登录？',
                        cancelLabel: "取消",
                        okLabel: "确定",
                        useRootNavigator: false,
                        fullyCapitalizedForMaterial: false,
                        barrierDismissible: false,
                        isDestructiveAction: true,
                        style: AdaptiveStyle.iOS,
                        defaultType: OkCancelAlertDefaultType.ok)
                        .then((value) {
                      controller.clickLogout();
                    });
                  }),
            );
          }
        },
        shrinkWrap: true,
        itemCount: 2,
      ),
    );
  }
}
